package com.play.ballen.home.ui

import android.content.Context
import android.content.Intent
import android.view.View
import com.play.ballen.R
import com.play.ballen.databinding.ActivityJubaoBinding
import com.play.ballen.event.EventCost
import com.play.ballen.home.vm.PLPFragmentVM
import com.yuven.appframework.util.setOnSingleClickListener
import com.yuven.baselib.component.BaseMVVMActivity
import com.yuven.baselib.component.eventbus.Event
import com.yuven.baselib.component.eventbus.EventBusUtil

class JubaoActivity : BaseMVVMActivity<PLPFragmentVM, ActivityJubaoBinding>() {

    var id: Int = 0

    var reason :String? = null
    companion object {
        @JvmStatic
        fun start(context: Context, data1: Int) {
            val starter = Intent(context, JubaoActivity::class.java)
            starter.putExtra("id", data1)
            context.startActivity(starter)
        }
    }
    override fun initIntent(intent: Intent?) {
        if (intent != null) {
            id = intent.getIntExtra("id",0)
        }
    }


    override fun layoutId(): Int {
        return  R.layout.activity_jubao
    }

    override fun viewModelClass(): Class<PLPFragmentVM> {
        return PLPFragmentVM::class.java
    }

    override fun initObserver() {
        super.initObserver()
        viewModel.reportSuccess.observe(this) {
            finish()
        }
    }

    override fun initView() {
        dataBinding.layoutTitle.tvTitleCenter.text = "举报"
        dataBinding.layoutTitle.ivBtnBack.setOnClickListener{
            finish()
        }
        dataBinding.btnok.setOnClickListener{
            val map = mutableMapOf<String, Any>()
            map["reason"] = reason.toString()
            map["id"] = id
            viewModel.reportBottle(map)
        }

        dataBinding.ll1.setOnSingleClickListener(onClickListener)
        dataBinding.ll2.setOnSingleClickListener(onClickListener)
        dataBinding.ll3.setOnSingleClickListener(onClickListener)
        dataBinding.ll4.setOnSingleClickListener(onClickListener)
        dataBinding.ll5.setOnSingleClickListener(onClickListener)
        dataBinding.ll6.setOnSingleClickListener(onClickListener)
        dataBinding.ll7.setOnSingleClickListener(onClickListener)

    }

    private val onClickListener = tag@{ v: View ->
        when (v.id) {
            R.id.ll_1 -> {
                checkPayType(1)
                reason = dataBinding.tv1.text.toString()
            }
            R.id.ll_2 ->{
                checkPayType(2)
                reason = dataBinding.tv2.text.toString()
            }
            R.id.ll_3 ->   {
                checkPayType(3)
                reason = dataBinding.tv3.text.toString()
            }
            R.id.ll_4 -> {
                checkPayType(4)
                reason = dataBinding.tv4.text.toString()
            }
            R.id.ll_5 ->    {
                checkPayType(5)
                reason = dataBinding.tv5.text.toString()
            }
            R.id.ll_6 ->{
                checkPayType(6)
                reason = dataBinding.tv6.text.toString()
            }
            R.id.ll_7 ->  {
                checkPayType(7)
                reason = dataBinding.etContent.text.toString()
            }
        }
    }

    private fun checkPayType(i: Int) {
        dataBinding.iv1.setBackgroundResource(if (i == 1) R.drawable.radio_select else R.drawable.radio_unselect)
        dataBinding.iv2.setBackgroundResource(if (i == 2) R.drawable.radio_select else R.drawable.radio_unselect)
        dataBinding.iv3.setBackgroundResource(if (i == 3) R.drawable.radio_select else R.drawable.radio_unselect)
        dataBinding.iv4.setBackgroundResource(if (i == 4) R.drawable.radio_select else R.drawable.radio_unselect)
        dataBinding.iv5.setBackgroundResource(if (i == 5) R.drawable.radio_select else R.drawable.radio_unselect)
        dataBinding.iv6.setBackgroundResource(if (i == 6) R.drawable.radio_select else R.drawable.radio_unselect)
        dataBinding.iv7.setBackgroundResource(if (i == 7) R.drawable.radio_select else R.drawable.radio_unselect)
    }
    override fun initData() {

    }

}